import { ImageUtil } from './ImageUtil';
import detectBarcode from "@hms.core.scan.detectBarcode";
import scanCore from "@hms.core.scan.scanCore";
export class ScanUtil {
    static async scanUrl(j18, k18, l18 = {
        scanTypes: [scanCore.ScanType.ALL],
        enableMultiMode: true,
        enableAlbum: true
    }) {
        const m18 = await ImageUtil.saveImageByUrl(j18, k18);
        return ScanUtil.scanUri(m18, l18);
    }
    static async scanPixelMap(f18, g18, h18 = {
        scanTypes: [scanCore.ScanType.ALL],
        enableMultiMode: true,
        enableAlbum: true
    }) {
        const i18 = await ImageUtil.saveImageByPixelMap(f18, g18);
        return ScanUtil.scanUri(i18, h18);
    }
    static scanUri(x17, y17 = {
        scanTypes: [scanCore.ScanType.ALL],
        enableMultiMode: true,
        enableAlbum: true
    }) {
        return new Promise((z17, a18) => {
            let b18 = { uri: x17 };
            detectBarcode.decode(b18, y17).then((d18) => {
                if (d18 != undefined) {
                    let e18 = d18[0]?.scanCodeRect;
                    if (e18 != undefined) {
                        if (d18[0]?.originalValue != undefined) {
                            z17(d18[0]?.originalValue ?? '');
                        }
                        else {
                            a18('scan error');
                        }
                        return;
                    }
                }
                a18('scan error');
            }).catch((c18) => {
                a18(c18.message);
            });
        });
    }
}
